package fun.sssdnsy.util;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

public class ThreadPoolUtil {

    /**
     * 用于摄像头/识别相关任务（单线程，避免 OpenCV 同步问题）
     */
    public static final ExecutorService FACE_POOL = Executors.newSingleThreadExecutor(r -> {
        Thread t = new Thread(r);
        t.setName("face-thread");
        t.setDaemon(true);
        return t;
    });

    /**
     * 通用异步任务池（CPU密集型）
     */
    public static final ExecutorService ASYNC_POOL = Executors.newFixedThreadPool(
            Runtime.getRuntime().availableProcessors(),
            r -> {
                Thread t = new Thread(r);
                t.setName("async-" + t.getId());
                return t;
            }
    );

    /**
     * 定时任务调度池（比如用在超时机制）
     */
    public static final ScheduledExecutorService SCHEDULED_THREAD_POOL = Executors.newScheduledThreadPool(2);
}
